#!/usr/bin/env python
# -*- coding: utf-8 

import SimpleHTTPServer
import SocketServer

class httpServer:
    global httpd
    global PORT
    def __init__(self):
        global httpd
        global PORT
    	PORT = 8000
        
	handler = SimpleHTTPServer.SimpleHTTPRequestHandler
	httpServerRunning = False
	while not httpServerRunning == True:
		try:
			httpd = SocketServer.TCPServer(("", PORT), handler)
			httpServerRunning = True
		except:
			httpServerRunning = False
			PORT = PORT + 1
			pass
    def startServer(self):
        global httpd
	httpd.serve_forever()
        pass

    def closeServer(self):
        global httpd
        try:
            httpd.socket.close()
        except:
            print "Couldn't close server port."
            pass
        pass

    def getPort(self):
        global PORT
        return PORT

    


    



